<body>
    <h2>用户动作追踪</h2>
    <div style="margin:10px 0;"></div>
    <table id="list"></table>
    
    <div id="tb" style="padding:5px;height:auto">
        <div style="margin-bottom:5px;vertical-align:middle">
            <a href="#" class="easyui-linkbutton"  plain="true">过滤条件：</a>
         	<a href="javascript:userTraceJs.openDateFilter()" class="easyui-linkbutton"  plain="true">时间</a>
    		
            <a href="#" class="easyui-menubutton" data-options="menu:'#mm3'">所有人</a>
                <div id="mm3" class="menu-content" style="background:#f0f0f0;padding:10px;text-align:middle;width:200px;height:100px">
    				<div class="ftitle">按照所有人搜索</div>
    			    <div id="employee_list">
            		</div> 
    			</div>
        </div>
        <div id="usertrace_date" style="padding:3px">
        	从:<input id="usertrace_from" type="text"></input>
        	到:<input id="usertrace_to" type="text"></input>
        	<span class="toolbar_pic"><a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:userTraceJs.searchByTime()" >搜索</a></span>
        </div>
        <div id="searchFilter">
        </div>
    </div>
    <script type="text/javascript">
(function(userTraceJs, $, undefined ) {     
	var countPerPage = 5;
	var start = 0;
	var usertrace_employee_search = '';
	
	userTraceJs.clearSearch = function()
	{
		countPerPage = 5;
		start = 0;
		usertrace_employee_search = '';
		$('#usertrace_from').datebox('setValue','');
		$('#usertrace_to').datebox('setValue','');
		refreshSearchFilter();
		refresh();
	};
	
	$('#list').datagrid({
		height:350,
		fitColumns:true,
		singleSelect:true,
		url:null,
		rownumbers:true,
	    columns:[[
					{title:'用户',field:'user',width:80},
	             	{title:'时间',field:'time',width:80,sortable:true},
	             	{title:'动作',field:'action',width:160,sortable:true},
	             ]],
		pagination:true,
        pageSize:countPerPage,
        pageList:[5,10,15,20,25],
		toolbar:'#tb',
	    onLoadSuccess: function(){   
	        $('#list').datagrid('loaded');
	    },
	});

	$('#list').datagrid('getPager').pagination({   
	    displayMsg:'当前显示从 [{from}] 到 [{to}] 共[{total}]条记录',   
	    onSelectPage : function(pPageIndex, pPageSize) {   
	    	
	        var gridOpts = $('#list').datagrid('options');   
	        gridOpts.pageNumber = pPageIndex;   
	        gridOpts.pageSize = pPageSize;     

	        start = (pPageIndex -1)*pPageSize;
	        loadData("dispatch/utility/usertrace/query?start="+start+'&size='+countPerPage,loadTraceData);
	    },
	    onChangePageSize : function(pageSize){
	    	countPerPage = pageSize;
	    }
	}); 
	userTraceJs.openDateFilter = function(){
		$('#usertrace_date').show();
	};
	userTraceJs.init = function(){
		$('#usertrace_from').datebox();
		$('#usertrace_to').datebox();
		refresh();
	};
	
	function loadData(url,func){
		$.ajax({
            type: "post",
            url: url,
            dataType:"json",
            success: function (result) {
            	func(result);
            }
            
        });
	};
	function loadTraceData(result){
    	var res = result.result;
        if(res == "SUCCESS")
        {
        	var payload = jQuery.parseJSON(result.payload.value);
        	$('#list').datagrid('loadData',payload);
        }else if(res == "COMPONENT_ERROR")
        {
        	$.messager.alert("Error",result.payload.value);
        }else
        {
        	$.messager.alert("Error",result.result);
        }
	};

    function refresh(){
    	$('#usertrace_date').hide();
    	loadData("dispatch/utility/usertrace/query?start="+start+"&size="+countPerPage,loadTraceData);
    	loadData("dispatch/manage/employee/simpleAll",loadEmployeeResult);
    };
    
    function loadEmployeeResult(result){
    	if(result.result == "SUCCESS")
    	{
    		var rows = jQuery.parseJSON(result.payload.value);
    		var html = "";
    		html+='<p><a href="#" onclick="javascript:userTraceJs.searchByEmployee(\'\')"> 全部</a></p>';
    		$(rows).each(function(index){
    			html+='<p><a href="#" onclick="javascript:userTraceJs.searchByEmployee(\''+rows[index].name+'\')"> '+rows[index].name+' </a></p>';
    		});
    		$('#employee_list').html(html);
    	}
    };
    userTraceJs.searchByEmployee = function(employee){
		usertrace_employee_search = employee;
		$('#list').datagrid("loading");
		refreshSearchFilter();
		start = 0;
		postSearch();
	};

    userTraceJs.searchByTime = function(){
		$('#list').datagrid("loading");
		refreshSearchFilter();
		start = 0;
		postSearch();
	};
	function getSearchFilter()
	{
		var html = "查询条件:";
		if(usertrace_employee_search != "" && typeof(usertrace_employee_search) != 'undefined')
			html += " + "+usertrace_employee_search;
		var usertrace_from = $('#usertrace_from').datebox('getValue');
		if(usertrace_from != "" && typeof(usertrace_from) != 'undefined')
			html += " + 时间从 "+usertrace_from;
		
		var usertrace_to = $('#usertrace_to').datebox('getValue');
		if(usertrace_to != "" && typeof(usertrace_to) != 'undefined')
			html += " + 时间到 "+usertrace_to;
		
		return html;
	};
	function refreshSearchFilter()
	{

		var html = getSearchFilter();
		html += ' <a href="javascript:void(0)" onclick="javascript:userTraceJs.clearSearch()">清除</a>';
		$('#searchFilter').html(html);
		
	};
	function postSearch()
	{
		var str = "";
		var usertrace_from = $('#usertrace_from').datebox('getValue');
		if(typeof(usertrace_from) == 'undefined')
			usertrace_from = '';
		
		var usertrace_to = $('#usertrace_to').datebox('getValue');
		if(typeof(usertrace_to) == 'undefined')
			usertrace_to = '';
		
		str = appendURL(str,"employee="+usertrace_employee_search);
		str = appendURL(str,"from="+usertrace_from);
		str = appendURL(str,"to="+usertrace_to);
		str = appendURL(str,'start='+start+'&size='+countPerPage);
		$.ajax({
            type: "post",
            url: "dispatch/utility/usertrace/query",
            dataType:"json",
            data: str,
            cache: false,
            success: function (result) {
            	
            	loadTraceData(result);
            }
		});
	};
	function appendURL(url,str1)
	{
		if(typeof(str1) == 'undefined')return url;
		if(url == "" || typeof(url) == 'undefined')url = str1;
		else url+="&"+str1;

		return url;
	};
}( window.userTraceJs = window.userTraceJs || {}, jQuery ));

    $(function(){
    	userTraceJs.init();
    });
    </script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .toolbar_pic {
 			width: 70px;
  			height: 30px;
  			overflow: hidden;
  			display: inline-block;
  			vertical-align: top;
  			cursor: pointer;
  			opacity: 0.6;
  			filter: alpha(opacity=60);
		}
		.toolbar_text {
 			width: 70px;
 			height:100%;
  			overflow: hidden;
  			display: inline-block;
  			vertical-align: middle;
		}
    </style>